package com.easyidea.its.domain.service.surveillance.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import com.easyidea.its.domain.model.surveillance.Alarm;
import com.easyidea.its.domain.repository.surveillance.AlarmRepository;
import com.easyidea.its.domain.service.base.impl.BaseBeanServiceImpl;
import com.easyidea.its.domain.service.surveillance.AlarmService;
import com.easyidea.its.util.StringUtil;
import com.easyidea.its.web.action.surveillance.dto.SurveillanceDto;
import com.easyidea.its.web.dto.AlarmTrackLogDto;

/**
 * 
 * @author hukn
 * 
 */
public class AlarmServiceImpl extends BaseBeanServiceImpl<Alarm, AlarmRepository> implements AlarmService {
	private AlarmRepository alarmRepository;

	@Override
	public AlarmRepository getBaseRepository() {
		return alarmRepository;
	}

	public AlarmRepository getAlarmRepository() {
		return alarmRepository;
	}

	public void setAlarmRepository(AlarmRepository alarmRepository) {
		this.alarmRepository = alarmRepository;
	}

	public int getAlarmCountByDto(SurveillanceDto searchDto) {

		return alarmRepository.getAlarmCountByDto(searchDto);
	}

	public Collection<Alarm> getAlarmByDto(SurveillanceDto searchDto, int start, int pageSize) {

		return alarmRepository.getAlarmByDto(searchDto, start, pageSize);
	}
	public Alarm getLatestAlarmByCondition(String passPortName, String direction) {
		passPortName = StringUtil.strDecode(passPortName);
		direction = StringUtil.strDecode(direction);		
		return alarmRepository.getLatestAlarmByCondition(passPortName, direction);
	}
	public boolean doDealWithAlarm(Integer alarmId) {
		return alarmRepository.doDealWithAlarm(alarmId);
	}
	public List<AlarmTrackLogDto> getLatestAlarm() {
		List<Object[]> atls = alarmRepository.getLatestAlarm();
		List<AlarmTrackLogDto> dtos = new ArrayList<AlarmTrackLogDto>();
		
		for (Object[] atl : atls) {
			AlarmTrackLogDto dto = new AlarmTrackLogDto();
			dto.setPlateNumber((String)atl[0]);
			dto.setPlateType((String)atl[1]);
			dto.setPassTime((Date)atl[2]);
			dto.setPassPortName((String)atl[3]);
			dto.setLaneName((String)atl[4]);
			dto.setSpeed((Integer)atl[5]);
			dto.setDirection((String)atl[6]);
			dto.setAlarmId((Integer)atl[7]);
			dtos.add(dto);
		}
		return dtos;
	}
}
